import requests
import time
import requests
import json


def sendRequest(url, method, js=None, headers=None, msg=None, data=None, params=None, oper=None):
    # 发送请求
    if oper != "login":
        token = headers.get('Authorization', None)
        if not token:
            raise Exception("未登录，请先登录")
    print(f"{msg}请求地址: {url}")
    if data:
        print(f"{msg}数据: {data}")
    if js:
        print(f"{msg}数据: {json.dumps(js)}")
    if params:
        print(f"{msg}参数: {params}")
    if headers:
        print(f"{msg}请求头: {headers}")
    res = requests.request(method, url, json=js,
                           headers=headers, data=data, params=params)
    if res.status_code == 200 or res.status_code == 204:
        print(f"{msg}成功")
        print(f"返回信息：{res.status_code} {res.text}")
        time.sleep(3)
    else:
        print(f"{msg}报错")
        print(f"报错信息：{res.status_code} {res.text}")
        # exit()
    return res
